home *** CD-ROM | disk | FTP | other *** search
/ internet.au CDrom 42 / NETCD42.iso / web / w95 / dream2.exe / data1.cab / Program_Files / Configuration / Behaviors / Actions / Check Browser.js < prev    next >
Encoding:
JavaScript  |  1998-11-30  |  6.4 KB  |  170 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //*************** GLOBALS VARS *****************
  4.  
  5. //******************* BEHAVIOR FUNCTION **********************
  6.  
  7. //Flexible interface allows many choices based on browser type an version.
  8. //If Netscape version meets or exceeds the first version, it can stay on the
  9. //same page of send the page to either of the URLs. Same for IE.
  10. //The function accepts the following arguments:
  11. //  NSvers   - float or integer: Netscape browser version number to check against
  12. //  NSpass   - 0,1,2: where to go if the browser version is the same or higher than NSvers:
  13. //               0 means stay on same page (do nothing)
  14. //               1 means go to theURL
  15. //               2 means go to altURL
  16. //  NSnoPass - 0,1,2: where to go if the browser version is the less than NSvers
  17. //  IEvers   - float or integer: Explorer browser version number to check against
  18. //  IEpass   - 0,1,2: where to go if the browser version is the same or higher than IEvers
  19. //  IEnoPass - 0,1,2: where to go if the browser version is the less than IEvers
  20. //  OBpass   - 0,1,2: where to go if other browser is used
  21. //  theURL   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  22. //  altURL   - URL, often a filename, URL encoded. (ex: file.htm, http://www.x.com/y.htm)
  23. //
  24. //Gets the client browser version number. Checks if the browser is Netscape.
  25. //If the version number >= NSvers, checks if NSpass > 0, then goes to URL or altURL based
  26. //on NSpass. Then does the same for Internet Explorer. If some other browser is use,
  27. //goes to the URL or altURL based on OBpass. Goes to a URL by setting the
  28. //window.location property. Sets the return value global so this code can override the
  29. //link HREF.
  30.  
  31. function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v2.0
  32.   var newURL = '', version = parseFloat(navigator.appVersion);
  33.   if (navigator.appName.indexOf('Netscape') != -1) {
  34.     if (version >= NSvers) {if (NSpass>0) newURL = (NSpass==1)?URL:altURL;}
  35.     else {if (NSnoPass>0) newURL = (NSnoPass==1)?URL:altURL;}
  36.   } else if (navigator.appName.indexOf('Microsoft') != -1) {
  37.     if (version >= IEvers) {if (IEpass>0) newURL = (IEpass==1)?URL:altURL;}
  38.     else {if (IEnoPass>0) newURL = (IEnoPass==1)?URL:altURL;}
  39.   } else if (OBpass>0) newURL = (OBpass==1)?URL:altURL;
  40.   if (newURL) {
  41.     window.location = unescape(newURL);
  42.     document.MM_returnValue = false;
  43.   }
  44. }
  45.  
  46.  
  47. //******************* API **********************
  48.  
  49.  
  50. //Can be used with any tag and any event
  51.  
  52. function canAcceptBehavior(){
  53.   return true;
  54. }
  55.  
  56.  
  57.  
  58. //Returns a Javascript function to be inserted in HTML head with script tags.
  59.  
  60. function behaviorFunction(){
  61.   return "MM_checkBrowser";
  62. }
  63.  
  64.  
  65.  
  66. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  67. //Calls escape to encode URLs. Checks validity of all entries.
  68. //For example, if *any* condition uses URL, the URL field cannot be empty.
  69.  
  70. function applyBehavior() {
  71.   var NSvers, IEvers, URL, altURL;
  72.   var NSpass, NSnoPass, IEpass, IEnoPass, OBpass;
  73.  
  74.   with (document.theForm) {  // read all values from form
  75.     NSvers = parseFloat(NSversion.value);
  76.     NSpass = NSpassTest.selectedIndex;
  77.     NSnoPass = NSnoPassTest.selectedIndex;
  78.     IEvers = parseFloat(IEversion.value);
  79.     IEpass = IEpassTest.selectedIndex;
  80.     IEnoPass = IEnoPassTest.selectedIndex;
  81.     OBpass = OBpassTest.selectedIndex;
  82.     URL = escape(theURL.value);  //URL encode
  83.     altURL = escape(theAltURL.value);  //URL encode
  84.   }
  85.  
  86.   //Check for valid numbers, and URLs exist if required
  87.   if (isNaN(NSvers) || isNaN(IEvers)) return MSG_InvalidVersionNumbers;
  88.   if ((URL=="") && (NSpass==1 || NSnoPass==1 || IEpass==1 || IEnoPass==1 || OBpass==1))
  89.      return MSG_NoURL;
  90.   if ((altURL=="") && (NSpass==2 || NSnoPass==2 || IEpass==2 || IEnoPass==2 || OBpass==2))
  91.      return MSG_NoAltURL;
  92.   
  93.   //Make sure numbers are floats 4 => 4.0
  94.   NSvers = ""+NSvers;
  95.   if (NSvers.indexOf(".") == -1) NSvers += ".0";
  96.   IEvers = ""+IEvers;
  97.   if (IEvers.indexOf(".") == -1) IEvers += ".0";
  98.  
  99.   return "MM_checkBrowser("+NSvers+","+NSpass+","+NSnoPass+","+IEvers+","+IEpass+","+IEnoPass+
  100.                           ","+OBpass+",'"+URL+"','"+altURL+"')";
  101. }
  102.  
  103.  
  104.  
  105. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  106. //call arguments. This information is used by DW to fixup behavior args when the
  107. //document is moved or changed.
  108. //
  109. //It is passed an actual function call string generated by applyBehavior(), which
  110. //may have a variable list of arguments, and this should return a matching mask.
  111. //
  112. //The return values are:
  113. //  URL     : argument could be a file path, which DW will update during Save As...
  114. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  115. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  116. //  other...: argument is ignored
  117.  
  118. function identifyBehaviorArguments(fnCallStr) {
  119.   var argArray;
  120.  
  121.   argArray = extractArgs(fnCallStr);
  122.   if (argArray.length == 10) {
  123.     return "other,other,other,other,other,other,other,URL,URL";
  124.   } else {
  125.     return "";
  126.   }
  127. }
  128.  
  129.  
  130.  
  131. //Passed the function call above, takes prior arguments and reloads the UI.
  132. //Converts strings into numbers for list indexes, and decodes URLs.
  133.  
  134. function inspectBehavior(argStr){
  135.   var argArray = extractArgs(argStr);
  136.  
  137.   if (argArray.length == 10) { //function name plus 9 args
  138.     with (document.theForm) {  // set all form values from args
  139.       NSversion.value            =          argArray[1];
  140.       NSpassTest.selectedIndex   = parseInt(argArray[2]);
  141.       NSnoPassTest.selectedIndex = parseInt(argArray[3]);
  142.       IEversion.value            =          argArray[4];
  143.       IEpassTest.selectedIndex   = parseInt(argArray[5]);
  144.       IEnoPassTest.selectedIndex = parseInt(argArray[6]);
  145.       OBpassTest.selectedIndex   = parseInt(argArray[7]);
  146.       theURL.value               = unescape(argArray[8]);
  147.       theAltURL.value            = unescape(argArray[9]);
  148.     }
  149.   }
  150. }
  151.  
  152.  
  153.  
  154. //**************** LOCAL FUNCTIONS ****************
  155.  
  156.  
  157. //Loads a preset list of browser version numbers
  158.  
  159. function initializeUI() {
  160.   document.theForm.theURL.focus(); //set focus on textbox
  161.   document.theForm.theURL.select(); //set insertion point into textbox
  162. }
  163.  
  164.  
  165.  
  166. //**************** GENERIC FUNCTIONS ****************
  167.  
  168. //function extractArgs(upStr){
  169. //function browseFile(fieldToStoreURL){
  170.